const app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    orderObj:{
      type:Object,
      value:null
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    time:"",
    role:null,
  },

  /**
   * 组件的方法列表
   */
  attached(){
   this.formateTime();
   this.setData({
     role:app.globalData.role
   })
  },
  methods: {
    formateTime(){
      if (!this.data.orderObj.createTime) {
        return;
      }
      // 实时时间
      let newTime = new Date();
      let y1 = newTime.getFullYear();
      let m1 = newTime.getMonth()+1;
      let d1 = newTime.getDate();
      // 订单时间
      let date = new Date(this.data.orderObj.createTime);
      let y = date.getFullYear();
      let m = date.getMonth()+1;
      let d = date.getDate();
      let hh = date.getHours();
      let mm = date.getMinutes();
      m = m<10?"0"+m:m;
      d  = d <10?"0"+d :d ;
      hh = hh<10?"0"+hh:hh;
      mm = mm<10?"0"+mm:mm;
      if(y1==y&&m1==m&&d1==d){
        this.setData({
          time:`今天 ${hh}:${mm}`
        })
      }else if(y1==y&&m1==m&&(d1-d)==1){
        this.setData({
          time:`昨天 ${hh}:${mm}`
        })
      }else if(y1==y){
        this.setData({
          time:`${m}月${d}日 ${hh}:${mm}`
        })
      }else{
        this.setData({
          time:`${y}年${m}月${d}日 ${hh}:${mm}`
        })
      }
    },
    switchPage(){
      let obj = this.data.orderObj;
      // 待审核
      if(obj.status == 0 || obj.status == 5){
        wx.navigateTo({
          url: '/pages/UnapproveOrder/UnapproveOrder?id='+obj._id,
        })
      }else if(obj.status == 1){
        // 待维修
        wx.navigateTo({
          url: '/pages/UnrepairOrder/UnrepairOrder?id='+obj._id,
        })
      }else if(obj.status == 2){
        // 待结单
        wx.navigateTo({
          url: '/pages/UnsettleOrder/UnsettleOrder?id='+obj._id,
        })
      }else if(obj.status == 3){
        // 待评价
        wx.navigateTo({
          url: '/pages/UnevaluateOrder/UnevaluateOrder?id='+obj._id,
        })
      }else if(obj.status == 4){
        // 已完成
       wx.navigateTo({
         url: '/pages/CompletedOrder/CompletedOrder?id='+obj._id,
       })
      }
    },
  }
})
